package com.zgkxzx.android.androidtest;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * 创建者 zgkxzx
 * 日期   2/5/18
 * 描述
 */

public class SecondActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//        RelativeLayout relativeLayout = new RelativeLayout(this);
//        View view = LayoutInflater.from(this).inflate(R.layout.activity_second, relativeLayout);


        requestWindowFeature(Window.FEATURE_LEFT_ICON);


        setContentView(R.layout.activity_second);
        //setContentView(relativeLayout);

        getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
                R.mipmap.ic_launcher);


        /*new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(8000000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();*/
    }

    @Override
    public void onContentChanged() {
        super.onContentChanged();
    }

    public static class LineItemView2 extends LinearLayout {

        private String title;
        private Bitmap icon;


        TextView tvTitle;
        ImageView ivIcon;

        public LineItemView2(Context context) {
            this(context, null);
        }

        public LineItemView2(Context context, AttributeSet attrs) {
            this(context, attrs, 0);
        }

        public LineItemView2(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
            inflate(context, R.layout.item_line, this);
            TypedArray type = context.obtainStyledAttributes(attrs, R.styleable.LineView);
            title = type.getString(R.styleable.LineView_itemTitle);
            icon = BitmapFactory.decodeResource(getResources(), type
                    .getResourceId(R.styleable.LineView_itemIcon,
                            R.mipmap.icon_alarm));
            type.recycle();
            setMinimumHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 56, context.getResources().getDisplayMetrics()));
            init();
        }

        private void init() {
            tvTitle = (TextView) findViewById(R.id.title_two_line);
            if (!TextUtils.isEmpty(title))
                tvTitle.setText(title);

            ivIcon = (ImageView) findViewById(R.id.iv_icon);
            ivIcon.setImageBitmap(icon);
        }

        public void setTitle(String title) {
            this.title = title;
            tvTitle.setText(title);
        }

        public String getTitle() {
            return title;
        }

        public void setIconImageRes(int resId) {
            ivIcon.setImageResource(resId);
        }

        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            return true;
        }
    }


}
